<template>
  <a-modal
    :open="open"
    width="1000px"
    title="危急值处理"
    centered
    :keyboard="false"
    :ok-button-props="{ disabled: !formState.crisisLisCode }"
    @ok="onOk"
    @cancel="onCancel"
  >
    <div class="flex flex-col">
      <BaseTable
        :height="300"
        :data-source="listData"
        :scroll="{ x: 400, y: 200 }"
        :loading="loading"
        column-code="00001116"
        :exclude-columns="['action', 'lastResult']"
        ex
      >
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex == 'xh'">
            <div class="flex justify-between">
              {{ index + 1 }}
              <RoundTag v-if="record.crisisStatus === '1'" bg-color="#f00">危</RoundTag>
            </div>
          </template>
          <template v-if="column.dataIndex === 'testResult'">
            <div class="flex items-center">
              <div class="pr-8" :class="{ 'text-red-500': +record.testResult > +record.minValue, 'text-green-500': +record.testResult < +record.maxValue }">
                {{ record.testResult }}
              </div>
              <div v-if="record.testResult" class="tip absolute right-4 text-2xl top-2 z-10">
                <div v-if="+record.testResult < +record.minValue" class="text-green-500">↓</div>
                <div v-if="+record.testResult > +record.maxValue" class="text-red-500">↑</div>
              </div>
            </div>
          </template>
          <template v-if="column.dataIndex === 'crisisValue'">
            <div>{{ record.crisisMinValue }}~{{ record.crisisMaxValue }}</div>
          </template>
        </template>
      </BaseTable>
      <a-form-item label="处理方式" class="mt-4" required>
        <SelectItem v-model:value="formState.crisisLisCode" type="DT00327" placeholder="请选择" />
      </a-form-item>
      <a-form-item label="备注">
        <a-textarea v-model:value="formState.crisisLisMemo" placeholder="请输入" />
      </a-form-item>
    </div>
  </a-modal>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import useStore from '../store'

const store = useStore()
defineProps({
  open: Boolean,
  listData: {
    type: Array,
    default: () => []
  }
})
const formState = ref({})
const emit = defineEmits(['update:open', 'success'])

const onOk = async () => {
  if (!formState.value.crisisLisCode) {
    return message.error('请选择处理方式')
  }
  const { code, msg } = await post('/lis/LisRecord/doConfirmCrisisAuditLisRecord', { ...formState.value, lisRecordId: store.currentData.lisRecord.id })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  onCancel()
  emit('success')
}
const onCancel = () => {
  emit('update:open', false)
  formState.value = {}
}
</script>
<style lang="less" scoped></style>
